﻿@{
    ViewBag.Title = "Регистрация пользователя";
}
@model ECatalog.Models.User

<div class="container">
    <div class="row">
        @using (Html.BeginForm("Save", "User", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <div class="form-group">
                <label for="Login" class="col-lg-2 control-label">Логин</label>
                <div class="col-lg-4">
                    @Html.TextBoxFor(model => model.Login, new { @placeholder = "Ваш уникальный логин...", @class = "form-control" })
                    @Html.LabelFor(model => model.Login, "Пользователь с таким логином уже зарегистрирован", new { id = "LoginValidateMessage", @class = "text-error hidden" })
                    @Html.ValidationMessageFor(model => model.Login)
                </div>
            </div>
            <div class="form-group">
                <label for="Password" class="col-lg-2 control-label">Пароль</label>
                <div class="col-lg-4">
                    @Html.PasswordFor(model => model.Password, new { @placeholder = "пароль...", @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.Password)
                </div>
            </div>
            <div class="form-group">
                <label for="IsAdmin" class="col-lg-2 "></label>
                <div class="col-lg-4">
                    <label class="control-label">@Html.EditorFor(model => model.IsAdmin)&nbsp;Администратор</label>
                    @Html.ValidationMessageFor(model => model.IsAdmin)
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-offset-2 col-lg-10">
                    <button type="submit" class="btn btn-primary">Зарегистрировать</button>
                </div>
            </div>
        }
    </div>
</div>
@section Scripts
{
    <script type="text/javascript">
        $(document).ready(function () {
            var login = $("#Login");
            var valLogin = $("#LoginValidateMessage");
            login.on("keyup", function () {
                if ($(this).val().length > 3) {
                    $.ajax({
                        type: "POST",
                        url: "\Validate",
                        data: { login: $(this).val() },
                        cache: false,
                        success: function (data) {
                            if (data == true) {
                                login.addClass("error-login");
                                valLogin.removeClass("hidden");
                            } else {
                                login.removeClass("error-login");
                                valLogin.addClass("hidden");
                            }
                        }
                    });
                }
            });
        });
    </script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
}
